<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title>
        <%= webpackConfig.name %>
    </title>
</head>

<body>
    <noscript>
      <strong>We're sorry but <%= webpackConfig.name %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->
</body>
<script>
    //offsetTop是元素与offsetParent的距离，循环获取直到页面顶部
    function getTop(e) {
        var T = e.offsetTop;
        while ((e = e.offsetParent)) {
            T += e.offsetTop;
        }
        return T;
    }

    function lazyLoad() {
        var imgs = document.querySelectorAll(".img");
        console.log(imgs);
        var H = document.getElementsByClassName("main-container")[0].clientHeight; //获取可视区域高度
        var S = document.getElementsByClassName("main-container")[0].scrollTop || document.getElementsByClassName("main-container")[0].scrollTop;
        for (var i = 0; i < imgs.length; i++) {
            if (H + S > getTop(imgs[i])) {
                imgs[i].classList.add("lazy-load");
            }
        }
    }
    window.lazyLoad = lazyLoad;
</script>

</html>